<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>装饰器 | MXY 1.0版Python整理</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../home/8.面向对象/5.抽象类.html" />
    
    
    <link rel="prev" href="../../home/8.面向对象/3.魔术方法.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="8.4"
        data-chapter-title="装饰器"
        data-filepath="home/8.面向对象/4.装饰器.md"
        data-basepath="../.."
        data-revision="Mon Oct 22 2018 08:32:35 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        MXY整理版Python基础
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" >
            
            <span><b>1.</b> Python的安装和简介</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="home/1.Python的安装和简介/1.python基础知识.html">
            
                
                    <a href="../../home/1.Python的安装和简介/1.python基础知识.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        Python的基础知识
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="home/1.Python的安装和简介/2.python的安装及版本检测.html">
            
                
                    <a href="../../home/1.Python的安装和简介/2.python的安装及版本检测.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        Python安装及版本检测
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="home/1.Python的安装和简介/3.第一个python程序.html">
            
                
                    <a href="../../home/1.Python的安装和简介/3.第一个python程序.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        第一个Python程序
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" >
            
            <span><b>2.</b> Python的基本语法</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="home/2.Python的基本语法/1.注释及语句分类.html">
            
                
                    <a href="../../home/2.Python的基本语法/1.注释及语句分类.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        注释及语句分类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="home/2.Python的基本语法/2.命名方式和关键字.html">
            
                
                    <a href="../../home/2.Python的基本语法/2.命名方式和关键字.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        命名方式和关键字
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" >
            
            <span><b>3.</b> Python的变量及数据类型</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="home/3.变量和数据类型/1.变量.html">
            
                
                    <a href="../../home/3.变量和数据类型/1.变量.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        变量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="home/3.变量和数据类型/2.数据类型.html">
            
                
                    <a href="../../home/3.变量和数据类型/2.数据类型.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        数据类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="home/3.变量和数据类型/3.数据类型转换.html">
            
                
                    <a href="../../home/3.变量和数据类型/3.数据类型转换.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        数据类型转换
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="home/3.变量和数据类型/4.运算和运算符.html">
            
                
                    <a href="../../home/3.变量和数据类型/4.运算和运算符.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        数据类型转换
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" >
            
            <span><b>4.</b> Python的流程控制</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="home/4.流程控制/1.顺序结构和分支结构.html">
            
                
                    <a href="../../home/4.流程控制/1.顺序结构和分支结构.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        顺序结构和分支结构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="home/4.流程控制/2.循环结构.html">
            
                
                    <a href="../../home/4.流程控制/2.循环结构.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        循环结构
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" >
            
            <span><b>5.</b> 函数及作用域</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="home/5.函数及作用域/1.函数.html">
            
                
                    <a href="../../home/5.函数及作用域/1.函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="home/5.函数及作用域/2.函数文档.html">
            
                
                    <a href="../../home/5.函数及作用域/2.函数文档.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        函数文档
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="home/5.函数及作用域/3.变量的作用域.html">
            
                
                    <a href="../../home/5.函数及作用域/3.变量的作用域.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        变量的作用域
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="home/5.函数及作用域/4.内部函数和闭包操作.html">
            
                
                    <a href="../../home/5.函数及作用域/4.内部函数和闭包操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        内部函数和闭包操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="home/5.函数及作用域/5.lambda表达式.html">
            
                
                    <a href="../../home/5.函数及作用域/5.lambda表达式.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        lambda表达式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="home/5.函数及作用域/6.高阶函数.html">
            
                
                    <a href="../../home/5.函数及作用域/6.高阶函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        高阶函数
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" >
            
            <span><b>6.</b> 内置函数及操作</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="home/6.内置函数及操作/1.字符串相关.html">
            
                
                    <a href="../../home/6.内置函数及操作/1.字符串相关.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        字符串相关
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="home/6.内置函数及操作/2.format格式字符串.html">
            
                
                    <a href="../../home/6.内置函数及操作/2.format格式字符串.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        format格式字符串
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="home/6.内置函数及操作/3.内建函数.html">
            
                
                    <a href="../../home/6.内置函数及操作/3.内建函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        内建函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="home/6.内置函数及操作/4.列表.html">
            
                
                    <a href="../../home/6.内置函数及操作/4.列表.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        列表
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="home/6.内置函数及操作/5.元组.html">
            
                
                    <a href="../../home/6.内置函数及操作/5.元组.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        元组
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="home/6.内置函数及操作/6.字典.html">
            
                
                    <a href="../../home/6.内置函数及操作/6.字典.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        字典
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="home/6.内置函数及操作/7.集合.html">
            
                
                    <a href="../../home/6.内置函数及操作/7.集合.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        集合
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="home/6.内置函数及操作/8.文件操作.html">
            
                
                    <a href="../../home/6.内置函数及操作/8.文件操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.8.</b>
                        
                        文件操作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" >
            
            <span><b>7.</b> 常用的模块</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="home/7.常用模块/1.String模块.html">
            
                
                    <a href="../../home/7.常用模块/1.String模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        String模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="home/7.常用模块/2.math模块.html">
            
                
                    <a href="../../home/7.常用模块/2.math模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        math模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="home/7.常用模块/3.OS模块.html">
            
                
                    <a href="../../home/7.常用模块/3.OS模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        OS模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="home/7.常用模块/4.zipfile模块.html">
            
                
                    <a href="../../home/7.常用模块/4.zipfile模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        zipfile模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="home/7.常用模块/5.tarfile模块.html">
            
                
                    <a href="../../home/7.常用模块/5.tarfile模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.5.</b>
                        
                        tarfile模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="home/7.常用模块/6.shutil模块.html">
            
                
                    <a href="../../home/7.常用模块/6.shutil模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.6.</b>
                        
                        shutil模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.7" data-path="home/7.常用模块/7.时间相关模块.html">
            
                
                    <a href="../../home/7.常用模块/7.时间相关模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.7.</b>
                        
                        时间相关模块
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" >
            
            <span><b>8.</b> 面向对象</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="home/8.面向对象/1.类和对象-上.html">
            
                
                    <a href="../../home/8.面向对象/1.类和对象-上.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        类和对象-上
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="home/8.面向对象/2.类和对象-下.html">
            
                
                    <a href="../../home/8.面向对象/2.类和对象-下.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        类和对象-下
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="home/8.面向对象/3.魔术方法.html">
            
                
                    <a href="../../home/8.面向对象/3.魔术方法.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        魔术方法
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="8.4" data-path="home/8.面向对象/4.装饰器.html">
            
                
                    <a href="../../home/8.面向对象/4.装饰器.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                        装饰器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.5" data-path="home/8.面向对象/5.抽象类.html">
            
                
                    <a href="../../home/8.面向对象/5.抽象类.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.5.</b>
                        
                        抽象类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.6" data-path="home/8.面向对象/6.错误和异常处理.html">
            
                
                    <a href="../../home/8.面向对象/6.错误和异常处理.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.6.</b>
                        
                        错误和异常处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.7" data-path="home/8.面向对象/7.模块和包.html">
            
                
                    <a href="../../home/8.面向对象/7.模块和包.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.7.</b>
                        
                        模块和包
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="9" >
            
            <span><b>9.</b> tkinter模块</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="home/9.tkinter模块/tkinter模块.html">
            
                
                    <a href="../../home/9.tkinter模块/tkinter模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        tkinter模块
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" data-path="home/10.网络编程/1.网络编程.html">
            
                
                    <a href="../../home/10.网络编程/1.网络编程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        网络编程
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="10.1" data-path="home/10.网络编程/2.TCP编程.html">
            
                
                    <a href="../../home/10.网络编程/2.TCP编程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.1.</b>
                        
                        TCP编程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.2" data-path="home/10.网络编程/3.UDP编程.html">
            
                
                    <a href="../../home/10.网络编程/3.UDP编程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.2.</b>
                        
                        UDP编程
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="11" data-path="home/11.多任务/多任务原理.html">
            
                
                    <a href="../../home/11.多任务/多任务原理.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.</b>
                        
                        多任务
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="11.1" data-path="home/11.多任务/1.多进程实现多任务.html">
            
                
                    <a href="../../home/11.多任务/1.多进程实现多任务.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.1.</b>
                        
                        多进程实现多任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.2" data-path="home/11.多任务/2.多线程实现多任务.html">
            
                
                    <a href="../../home/11.多任务/2.多线程实现多任务.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.2.</b>
                        
                        多线程实现多任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.3" data-path="home/11.多任务/3.协程实现多任务.html">
            
                
                    <a href="../../home/11.多任务/3.协程实现多任务.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.3.</b>
                        
                        协程实现多任务
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="12" >
            
            <span><b>12.</b> Python实战项目</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="12.1" data-path="home/12.Python实战项目/1.简易计算器.html">
            
                
                    <a href="../../home/12.Python实战项目/1.简易计算器.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.1.</b>
                        
                        简易计算器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.2" data-path="home/12.Python实战项目/2.自动售货机.html">
            
                
                    <a href="../../home/12.Python实战项目/2.自动售货机.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.2.</b>
                        
                        自动售货机
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.3" data-path="home/12.Python实战项目/3.银行项目.html">
            
                
                    <a href="../../home/12.Python实战项目/3.银行项目.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.3.</b>
                        
                        银行项目
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.4" data-path="home/12.Python实战项目/4.简单的登录注册.html">
            
                
                    <a href="../../home/12.Python实战项目/4.简单的登录注册.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.4.</b>
                        
                        简单的登录注册
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.5" data-path="home/12.Python实战项目/5.双色球.html">
            
                
                    <a href="../../home/12.Python实战项目/5.双色球.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.5.</b>
                        
                        双色球
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.6" data-path="home/12.Python实战项目/6.python垃圾回收机制.html">
            
                
                    <a href="../../home/12.Python实战项目/6.python垃圾回收机制.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.6.</b>
                        
                        python垃圾回收机制
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.7" data-path="home/12.Python实战项目/7.turtle画国旗.html">
            
                
                    <a href="../../home/12.Python实战项目/7.turtle画国旗.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.7.</b>
                        
                        turtle画国旗
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.8" data-path="home/12.Python实战项目/8.turtle画小猪佩奇.html">
            
                
                    <a href="../../home/12.Python实战项目/8.turtle画小猪佩奇.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.8.</b>
                        
                        turtle画小猪佩奇
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.9" data-path="home/12.Python实战项目/9.turtle画个表.html">
            
                
                    <a href="../../home/12.Python实战项目/9.turtle画个表.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.9.</b>
                        
                        turtle画个表
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >MXY 1.0版Python整理</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x88C5;&#x9970;&#x5668;">&#x88C5;&#x9970;&#x5668;</h1>
<hr>
<ul>
<li><h3 id="&#x4E3A;&#x666E;&#x901A;&#x51FD;&#x6570;&#x88C5;&#x9970;&#x5668;">&#x4E3A;&#x666E;&#x901A;&#x51FD;&#x6570;&#x88C5;&#x9970;&#x5668;</h3>
<pre><code class="lang-py">  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">adorn</span><span class="hljs-params">(func)</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">inner</span><span class="hljs-params">()</span>:</span>
          print(<span class="hljs-string">&apos;&#x4EBA;&#x4E4B;&#x521D;&apos;</span>)
          func()
          print(<span class="hljs-string">&apos;&#x6027;&#x76F8;&#x8FD1;&apos;</span>)
      <span class="hljs-keyword">return</span> inner

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">hanshu</span><span class="hljs-params">()</span>:</span>
      print(<span class="hljs-string">&apos;&#x6027;&#x672C;&#x5584;&apos;</span>)

  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
      hanshu = adorn(hanshu)
      hanshu()
</code></pre>
</li>
<li><h3 id="&#x4E3A;&#x5E26;&#x6709;&#x53C2;&#x6570;&#x7684;&#x51FD;&#x6570;&#x6DFB;&#x52A0;&#x88C5;&#x9970;&#x5668;">&#x4E3A;&#x5E26;&#x6709;&#x53C2;&#x6570;&#x7684;&#x51FD;&#x6570;&#x6DFB;&#x52A0;&#x88C5;&#x9970;&#x5668;</h3>
<pre><code class="lang-py">  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">adorn</span><span class="hljs-params">(func)</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">inner</span><span class="hljs-params">(who)</span>:</span>
          func(who)
          print(<span class="hljs-string">&apos;&#x6027;&#x672C;&#x5584;&apos;</span>)
          print(<span class="hljs-string">&apos;&#x6027;&#x76F8;&#x8FD1;&apos;</span>)

  <span class="hljs-comment"># @&#x662F;&#x8BED;&#x6CD5;&#x7CD6;</span>
<span class="hljs-decorator">  @adorn    </span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">hanshu</span><span class="hljs-params">(who)</span>:</span>
      print(<span class="hljs-string">&apos;{}&#x8BF4;&apos;</span>.format(who))
      print(<span class="hljs-string">&apos;&#x4EBA;&#x4E4B;&#x521D;&apos;</span>)

  <span class="hljs-comment"># hanshu = adorn(hanshu)    == @adorn</span>

  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
      hanshu(<span class="hljs-string">&apos;&#x5B54;&#x5B50;&apos;</span>)
</code></pre>
</li>
<li><h3 id="&#x4E3A;&#x5E26;&#x6709;&#x8FD4;&#x56DE;&#x503C;&#x7684;&#x51FD;&#x6570;&#x6DFB;&#x52A0;&#x88C5;&#x9970;&#x5668;">&#x4E3A;&#x5E26;&#x6709;&#x8FD4;&#x56DE;&#x503C;&#x7684;&#x51FD;&#x6570;&#x6DFB;&#x52A0;&#x88C5;&#x9970;&#x5668;</h3>
<pre><code class="lang-py">  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">adorn</span><span class="hljs-params">(func)</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">inner</span><span class="hljs-params">()</span>:</span>
          result = func()
          print(<span class="hljs-string">&apos;&#x6027;&#x672C;&#x5584;&apos;</span>)
          print(<span class="hljs-string">&apos;&#x6027;&#x76F8;&#x8FD1;&apos;</span>)
          <span class="hljs-keyword">return</span> result
      <span class="hljs-keyword">return</span> inner

<span class="hljs-decorator">  @adorn</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">hanshu</span><span class="hljs-params">()</span>:</span>
      print(<span class="hljs-string">&apos;&#x4EBA;&#x4E4B;&#x521D;&apos;</span>)
      <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;&#x4E09;&#x65A4;&#x4EC1;&#x4E49;&#x9053;&#x5FB7;&apos;</span>

  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
      result = hanshu()
      print(result)
</code></pre>
</li>
<li><h3 id="&#x4E3A;&#x5E26;&#x6709;&#x8FD4;&#x56DE;&#x503C;&#x548C;&#x5F62;&#x53C2;&#x7684;&#x51FD;&#x6570;&#x6DFB;&#x52A0;&#x88C5;&#x9970;&#x5668;">&#x4E3A;&#x5E26;&#x6709;&#x8FD4;&#x56DE;&#x503C;&#x548C;&#x5F62;&#x53C2;&#x7684;&#x51FD;&#x6570;&#x6DFB;&#x52A0;&#x88C5;&#x9970;&#x5668;</h3>
<pre><code class="lang-py">  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">adorn</span><span class="hljs-params">(func)</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">inner</span><span class="hljs-params">(who)</span>:</span>
          result = func(who)
          print(<span class="hljs-string">&apos;&#x6027;&#x672C;&#x5584;&apos;</span>)
          print(<span class="hljs-string">&apos;&#x6027;&#x76F8;&#x8FD1;&apos;</span>)
          <span class="hljs-keyword">return</span> result
      <span class="hljs-keyword">return</span> inner

<span class="hljs-decorator">  @adorn</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">hanshu</span><span class="hljs-params">(who)</span>:</span>
      print(<span class="hljs-string">&apos;{}&#x8BF4;&apos;</span>.format(who))
      print(<span class="hljs-string">&apos;&#x4EBA;&#x4E4B;&#x521D;&apos;</span>)
      <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;&#x4E8C;&#x4E24;&#x4EC1;&#x4E49;&#x9053;&#x5FB7;&apos;</span>

  <span class="hljs-comment"># hanshu = adorn(hanshu)</span>

  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
      result = hanshu(<span class="hljs-string">&apos;&#x5B54;&#x5B50;&apos;</span>)
      print(result)
</code></pre>
</li>
<li><h3 id="&#x4E3A;&#x5E26;&#x6709;&#x641C;&#x96C6;&#x53C2;&#x6570;&#x7684;&#x51FD;&#x6570;&#x6DFB;&#x52A0;&#x88C5;&#x9970;&#x5668;">&#x4E3A;&#x5E26;&#x6709;&#x641C;&#x96C6;&#x53C2;&#x6570;&#x7684;&#x51FD;&#x6570;&#x6DFB;&#x52A0;&#x88C5;&#x9970;&#x5668;</h3>
<pre><code class="lang-py">  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">adorn</span><span class="hljs-params">(func)</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">inner</span><span class="hljs-params">(*who)</span>:</span>
          func(*who)
          print(<span class="hljs-string">&apos;&#x7136;&#x800C;&#x4ED6;&#x4EEC;&#x8BF4;&#x7684;&#x8BDD;&#x6211;&#x8BB0;&#x4F4F;&#x7684;&#x5E76;&#x4E0D;&#x591A;&apos;</span>)
          print(<span class="hljs-string">&apos;&#x53EA;&#x77E5;&#x9053;,&#x4EBA;&#x4E4B;&#x521D;......&apos;</span>)
      <span class="hljs-keyword">return</span> inner

<span class="hljs-decorator">  @adorn</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">hanshu</span><span class="hljs-params">(*who)</span>:</span>
      string = <span class="hljs-string">&apos;&apos;</span>
      <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> who:
          string += (i+<span class="hljs-string">&apos;,&apos;</span>)
      print(<span class="hljs-string">&apos;{}&#x8FD9;&#x4E9B;&#x4EBA;&#x90FD;&#x662F;&#x53E4;&#x4EE3;&#x7684;&#x5148;&#x8D24;&apos;</span>.format(string))

  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
      hanshu(<span class="hljs-string">&apos;&#x5B54;&#x5B50;&apos;</span>,<span class="hljs-string">&apos;&#x5B5F;&#x5B50;&apos;</span>,<span class="hljs-string">&apos;&#x97E9;&#x975E;&#x5B50;&apos;</span>,<span class="hljs-string">&apos;&#x8340;&#x5B50;&apos;</span>)
</code></pre>
</li>
<li><h3 id="&#x4F7F;&#x7528;&#x7C7B;&#x4F5C;&#x4E3A;&#x88C5;&#x9970;&#x5668;&#x7684;&#x53C2;&#x6570;&#x7528;&#x7C7B;&#x7684;&#x4E2D;&#x7684;&#x65B9;&#x6CD5;&#x88C5;&#x9970;&#x51FD;&#x6570;">&#x4F7F;&#x7528;&#x7C7B;&#x4F5C;&#x4E3A;&#x88C5;&#x9970;&#x5668;&#x7684;&#x53C2;&#x6570;(&#x7528;&#x7C7B;&#x7684;&#x4E2D;&#x7684;&#x65B9;&#x6CD5;&#x88C5;&#x9970;&#x51FD;&#x6570;)</h3>
<pre><code class="lang-py">  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">adorn</span><span class="hljs-params">(cls)</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">_adorn</span><span class="hljs-params">(func)</span>:</span>
          <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">inner</span><span class="hljs-params">(**who)</span>:</span>
              func(**who)
              cls.kongzi()
              cls.xunzi()
          <span class="hljs-keyword">return</span> inner
      <span class="hljs-keyword">return</span> _adorn

  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Perf</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">kongzi</span><span class="hljs-params">()</span>:</span>
          print(<span class="hljs-string">&apos;&#x4E09;&#x4EBA;&#x884C;&#x5FC5;&#x6709;&#x6211;&#x5E08;&apos;</span>)
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">xunzi</span><span class="hljs-params">()</span>:</span>
          print(<span class="hljs-string">&apos;&#x4EBA;&#x4E4B;&#x521D;,&#x6027;&#x672C;&#x6076;&apos;</span>)

<span class="hljs-decorator">  @adorn(Perf)</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">hanshu</span><span class="hljs-params">(**who)</span>:</span>
      string = <span class="hljs-string">&apos;&apos;</span>
      <span class="hljs-keyword">for</span> x,y <span class="hljs-keyword">in</span> who.items():
          string += (y+<span class="hljs-string">&apos;,&apos;</span>)
      print(string + <span class="hljs-string">&apos;&#x8FD9;&#x4E9B;&#x4EBA;&#x90FD;&#x662F;&#x53E4;&#x4EE3;&#x5148;&#x8D24;&apos;</span>)
      print(<span class="hljs-string">&apos;&#x4ED6;&#x4EEC;&#x8BF4;&#x8FC7;:&apos;</span>)

  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
      hanshu(kz = <span class="hljs-string">&apos;&#x5B54;&#x5B50;&apos;</span>, xunzi = <span class="hljs-string">&apos;&#x8340;&#x5B50;&apos;</span>)
</code></pre>
</li>
<li><h3 id="&#x4E00;&#x4E2A;&#x88C5;&#x9970;&#x5668;&#x88C5;&#x9970;&#x591A;&#x4E2A;&#x51FD;&#x6570;">&#x4E00;&#x4E2A;&#x88C5;&#x9970;&#x5668;&#x88C5;&#x9970;&#x591A;&#x4E2A;&#x51FD;&#x6570;</h3>
<pre><code class="lang-py">  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">adorn</span><span class="hljs-params">(flag)</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">_adorn</span><span class="hljs-params">(func)</span>:</span>
          <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">inner</span><span class="hljs-params">()</span>:</span>
              <span class="hljs-keyword">if</span> flag == <span class="hljs-string">&apos;mxy&apos;</span>:
                  func()
                  print(<span class="hljs-string">&apos;&#x53EA;&#x613F;&#x5317;&#x51C9;&#x4E0D;&#x60B2;&#x51C9;&apos;</span>)
                  print(<span class="hljs-string">&apos;&#x5317;&#x51C9;&#x613F;&#x4E3A;&#x5929;&#x4E0B;&#x9ECE;&#x6C11;&#x5B88;&#x56FD;&#x95E8;!&apos;</span>)
              <span class="hljs-keyword">elif</span> flag == <span class="hljs-string">&apos;jxy&apos;</span>:
                  func()
                  print(<span class="hljs-string">&apos;&#x4F60;&#x8981;&#x5929;&#x4E0B;,&#x6211;&#x4E3A;&#x4F60;&#x6253;&#x4E0B;&#x4E00;&#x5EA7;&#x5929;&#x4E0B;&apos;</span>)
                  print(<span class="hljs-string">&apos;&#x4F60;&#x8981;&#x6C5F;&#x6E56;,&#x6211;&#x7ED9;&#x4F60;&#x8E0F;&#x5E73;&#x4E00;&#x5EA7;&#x6C5F;&#x6E56;&apos;</span>)
                  print(<span class="hljs-string">&apos;&#x6211;&#x53EA;&#x8981;&#x4E00;&#x4E2A;&#x5B69;&#x5B50;&apos;</span>)
                  print(<span class="hljs-string">&apos;&#x4F60;&#x7ED9;&#x4E0D;&#x7ED9;?&apos;</span>)
          <span class="hljs-keyword">return</span> inner
      <span class="hljs-keyword">return</span> _adorn

<span class="hljs-decorator">  @adorn(&apos;mxy&apos;)</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">hanshu1</span><span class="hljs-params">()</span>:</span>
      print(<span class="hljs-string">&apos;mxy&#x8BF4;&#x8FC7;&apos;</span>)

<span class="hljs-decorator">  @adorn(&apos;jxy&apos;)</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">hanshu2</span><span class="hljs-params">()</span>:</span>
      print(<span class="hljs-string">&apos;jxy&#x8BF4;&#x8FC7;&apos;</span>)

  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
      hanshu1()
      hanshu2()
</code></pre>
</li>
</ul>
<ul>
<li><h3 id="&#x4F7F;&#x7528;&#x7C7B;&#x4F5C;&#x4E3A;&#x88C5;&#x9970;&#x5668;&#x88C5;&#x9970;&#x51FD;&#x6570;">&#x4F7F;&#x7528;&#x7C7B;&#x4F5C;&#x4E3A;&#x88C5;&#x9970;&#x5668;&#x88C5;&#x9970;&#x51FD;&#x6570;</h3>
<pre><code class="lang-py">  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Adorn</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, flag)</span>:</span>
          self.flag = flag

      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__call__</span><span class="hljs-params">(self, func)</span>:</span>
          self.func = func
          <span class="hljs-keyword">if</span> self.flag == <span class="hljs-string">&apos;mxy&apos;</span>:
              <span class="hljs-keyword">return</span> self.inner1
          <span class="hljs-keyword">elif</span> self.flag == <span class="hljs-string">&apos;jxy&apos;</span>:
              <span class="hljs-keyword">return</span> self.inner2

      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">inner1</span><span class="hljs-params">(self)</span>:</span>
          self.func()
          print(<span class="hljs-string">&apos;&#x5982;&#x679C;&#x4F60;&#x6B7B;&#x4E86;&apos;</span>)
          print(<span class="hljs-string">&apos;&#x4F60;&#x7684;&#x5C38;&#x9996;&#x5728;&#x54EA;&#x91CC;&apos;</span>)
          print(<span class="hljs-string">&apos;&#x6211;&#x5C31;&#x5728;&#x54EA;&#x91CC;&apos;</span>)

      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">inner2</span><span class="hljs-params">(self)</span>:</span>
          self.func()
          print(<span class="hljs-string">&apos;&#x6211;&#x6765;&#x63A5;&#x6211;&#x5AB3;&#x5987;&apos;</span>)
          print(<span class="hljs-string">&apos;&#x8C01;&#x6562;&#x62E6;&#x6211;!&apos;</span>)

<span class="hljs-decorator">  @Adorn(&apos;mxy&apos;)</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">hanshu1</span><span class="hljs-params">()</span>:</span>
      print(<span class="hljs-string">&apos;jxy&#x8BF4;&#x8FC7;&apos;</span>)

<span class="hljs-decorator">  @Adorn(&apos;jxy&apos;)</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">hanshu2</span><span class="hljs-params">()</span>:</span>
      print(<span class="hljs-string">&apos;mxy&#x8BF4;&#x8FC7;&apos;</span>)

  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
      hanshu1()
      hanshu2()
</code></pre>
</li>
<li><h3 id="&#x4F7F;&#x7528;&#x51FD;&#x6570;&#x4F5C;&#x4E3A;&#x88C5;&#x9970;&#x5668;&#x6765;&#x88C5;&#x9970;&#x7C7B;">&#x4F7F;&#x7528;&#x51FD;&#x6570;&#x4F5C;&#x4E3A;&#x88C5;&#x9970;&#x5668;&#x6765;&#x88C5;&#x9970;&#x7C7B;</h3>
<pre><code class="lang-py">  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">adorn</span><span class="hljs-params">(cls)</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">inner</span><span class="hljs-params">()</span>:</span>
          print(<span class="hljs-string">&apos;&#x7ED9;&#x4F60;&#x52A0;&#x4E2A;&#x529F;&#x80FD;,&#x8FD8;&#x8981;&#x4FDD;&#x7559;&#x4F60;&#x5B9E;&#x4F8B;&#x5316;&#x7684;&#x529F;&#x80FD;&apos;</span>)
          obj = cls()
          print(<span class="hljs-string">&apos;&#x6765;&#x6211;&#x8FD9;&#x91CC;&#x4F60;&#x51FA;&#x53BB;&#x5C31;&#x53D8;&#x6210;function&#x4E86;,&#x96BE;&#x8FC7;&#x4E48;&apos;</span>)
          <span class="hljs-keyword">return</span> obj
      <span class="hljs-keyword">return</span> inner

<span class="hljs-decorator">  @adorn</span>
  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">BeiLiang</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">method1</span><span class="hljs-params">(self)</span>:</span>
          print(<span class="hljs-string">&apos;&#x7528;&#x4E0D;&#x4E0A;....&#x771F;&#x5C34;&#x5C2C;&apos;</span>)
  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
      obj = BeiLiang()
      print(obj)
</code></pre>
</li>
<li><h3 id="&#x591A;&#x5C42;&#x5D4C;&#x5957;&#x7684;&#x88C5;&#x9970;&#x5668;">&#x591A;&#x5C42;&#x5D4C;&#x5957;&#x7684;&#x88C5;&#x9970;&#x5668;</h3>
<pre><code class="lang-py">  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">adorn1</span><span class="hljs-params">(func)</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">inner</span><span class="hljs-params">()</span>:</span>
          print(<span class="hljs-string">&apos;&#x5929;&#x4E0D;&#x751F;&#x6211;&#x674E;&#x6DF3;&#x7F61;&apos;</span>)
          func()
          print(<span class="hljs-string">&apos;&#x4E00;&#x5251;&#x5E73;&#x5929;&#x4E0B;&#x4E0D;&#x5E73;&#x4E8B;&apos;</span>)
      <span class="hljs-keyword">return</span> inner

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">adorn2</span><span class="hljs-params">(func)</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">inner</span><span class="hljs-params">()</span>:</span>
          print(<span class="hljs-string">&apos;&#x4E00;&#x628A;&#x6728;&#x9A6C;&#x725B;,&#x9752;&#x886B;&#x4ED7;&#x5251;&#x72EC;&#x98CE;&#x6D41;&apos;</span>)
          func()
          print(<span class="hljs-string">&apos;&#x4E00;&#x5251;&#x65E0;&#x6127;&#x5929;&#x4E0B;&#x6709;&#x6127;&#x4EBA;&apos;</span>)
      <span class="hljs-keyword">return</span> inner

<span class="hljs-decorator">  @adorn2</span>
<span class="hljs-decorator">  @adorn1</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">lichungang</span><span class="hljs-params">()</span>:</span>
      print(<span class="hljs-string">&apos;&#x5251;&#x9053;&#x4E07;&#x53E4;&#x5982;&#x957F;&#x591C;&apos;</span>)

  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
      lichungang()
</code></pre>
</li>
<li><h3 id="&#x4F7F;&#x7528;&#x7C7B;&#x4F5C;&#x4E3A;&#x88C5;&#x9970;&#x5668;&#x6765;&#x88C5;&#x9970;&#x7C7B;">&#x4F7F;&#x7528;&#x7C7B;&#x4F5C;&#x4E3A;&#x88C5;&#x9970;&#x5668;&#x6765;&#x88C5;&#x9970;&#x7C7B;</h3>
<pre><code class="lang-py">  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Adorn</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self,flag)</span>:</span>
          <span class="hljs-keyword">pass</span>

      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__call__</span><span class="hljs-params">(self,cls)</span>:</span>
          self.cls = cls
          <span class="hljs-keyword">return</span> self.inner

      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">inner</span><span class="hljs-params">(self)</span>:</span>
          print(<span class="hljs-string">&apos;&#x6211;&#x8981;&#x5F00;&#x59CB;&#x5B9E;&#x4F8B;&#x5316;&#x4E86;&apos;</span>)
          obj = self.cls()
          print(<span class="hljs-string">&apos;&#x6211;&#x5DF2;&#x7ECF;&#x4E0D;&#x662F;&#x7C7B;&#x4E86;...&apos;</span>)
          <span class="hljs-keyword">return</span> obj

<span class="hljs-decorator">  @Adorn(&apos;&#x6709;&#x6CA1;&#x6709;&#x90FD;&#x4E00;&#x6837;&apos;)</span>
  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">BeiLiang</span>:</span>
      name = <span class="hljs-string">&apos;&#x5360;&#x4F4D;&apos;</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test</span><span class="hljs-params">(self)</span>:</span>
          print(<span class="hljs-string">&apos;&#x5509;,&#x7528;&#x4E0D;&#x4E0A;,&#x5355;&#x7EAF;&#x5360;&#x4F4D;&apos;</span>)

  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
      b = BeiLiang()
      print(b)
</code></pre>
</li>
</ul>
<ul>
<li><h3 id="&#x8D77;&#x5230;&#x4FEE;&#x9970;&#x6570;&#x636E;&#x7684;&#x4F5C;&#x7528;">&#x8D77;&#x5230;&#x4FEE;&#x9970;&#x6570;&#x636E;&#x7684;&#x4F5C;&#x7528;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># &#x53EF;&#x4EE5;&#x5C06;&#x4E0D;&#x89C4;&#x8303;&#x7684;&#x5E74;&#x9F84;&#x8FC7;&#x6EE4;&#x6210;0</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">outer</span><span class="hljs-params">(func)</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">inner</span><span class="hljs-params">(age)</span>:</span>
          <span class="hljs-keyword">if</span> age &lt; <span class="hljs-number">0</span>:
              age = <span class="hljs-number">0</span>
          func(age)
      <span class="hljs-keyword">return</span> inner

  <span class="hljs-comment"># &#x4F7F;&#x7528;@&#x7B26;&#x53F7;&#x5C06;&#x88C5;&#x9970;&#x5668;&#x5E94;&#x7528;&#x5230;&#x51FD;&#x6570;</span>
<span class="hljs-decorator">  @outer      # &#x76F8;&#x5F53;&#x4E8E;say = outer(say)</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">say</span><span class="hljs-params">(age)</span>:</span>
      print(<span class="hljs-string">&quot;meng is %d years old&quot;</span> % age)

  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
      <span class="hljs-comment"># say = outer(say)</span>
      say(-<span class="hljs-number">10</span>)
</code></pre>
</li>
<li><h3 id="&#x901A;&#x7528;&#x88C5;&#x9970;&#x5668;">&#x901A;&#x7528;&#x88C5;&#x9970;&#x5668;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">outer</span><span class="hljs-params">(func)</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">inner</span><span class="hljs-params">(*args, **kwargs)</span>:</span>
          <span class="hljs-comment"># &#x6DFB;&#x52A0;&#x4FEE;&#x9970;&#x7684;&#x529F;&#x80FD;</span>
          print(<span class="hljs-string">&quot;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&quot;</span>)
          func(*args, **kwargs)
      <span class="hljs-keyword">return</span> inner

<span class="hljs-decorator">  @outer</span>
  <span class="hljs-comment"># &#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x7406;&#x8BBA;&#x4E0A;&#x662F;&#x65E0;&#x9650;&#x5236;&#x7684;&#xFF0C;&#x4F46;&#x5B9E;&#x9645;&#x4E0A;&#x6700;&#x597D;&#x4E0D;&#x597D;&#x8D85;&#x8FC7;6-7&#x4E2A;</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">say</span><span class="hljs-params">(name, age=<span class="hljs-number">28</span>)</span>:</span>
      print(<span class="hljs-string">&quot;my name is %s, I am %d years old&quot;</span> % (name, age))

  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
      say(<span class="hljs-string">&quot;meng&quot;</span>, age=<span class="hljs-number">1</span>)
</code></pre>
<p>  ```py</p>
<h1 id="codingutf8-">-<em>- coding:utf-8 -</em>-</h1>
<p>  import time</p>
<p>  def foo(num):</p>
<pre><code>  def outer(fun):
      def inner(*args, **kwargs):
          start_time = time.time()
          for i in range(num):
              fun(*args, **kwargs)
          run_time = time.time() - start_time
          return run_time
      return inner
  return outer
</code></pre></li>
</ul>
<pre><code>@foo(5)
def func(user, name, pwd):
    for i in range(9999999):
        pass
    print(user, &quot;say hello to&quot;, name, pwd)

run = func(&quot;rose&quot;, &quot;jack&quot;, 123)
print(run)

```
</code></pre><hr>
<h1 id="&#x65B9;&#x6CD5;&#x7684;&#x5206;&#x7C7B;">&#x65B9;&#x6CD5;&#x7684;&#x5206;&#x7C7B;</h1>
<ul>
<li><h3 id="&#x7ED1;&#x5B9A;&#x7C7B;&#x65B9;&#x6CD5;">&#x7ED1;&#x5B9A;&#x7C7B;&#x65B9;&#x6CD5;</h3>
<pre><code class="lang-py">  &#x7ED1;&#x5B9A;&#x7C7B;&#x65B9;&#x6CD5;&#x5C31;&#x662F;&#x7C7B;&#x4E2D;&#x53EA;&#x80FD;&#x7531;&#x7C7B;&#x8C03;&#x7528;&#x7684;&#x65B9;&#x6CD5;,&#x4E0D;&#x5E26;&#x4EFB;&#x4F55;&#x53C2;&#x6570;&#x63A5;&#x6536;&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x6CD5;(&#x6CA1;&#x6709;self&#x7684;&#x65B9;&#x6CD5;)
  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Human</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">eat</span><span class="hljs-params">()</span>:</span>
          print(<span class="hljs-string">&apos;&#x7ED1;&#x5B9A;&#x7C7B;&#x65B9;&#x6CD5;,&#x5BF9;&#x8C61;&#x65E0;&#x6CD5;&#x8C03;&#x7528;&apos;</span>)
</code></pre>
</li>
<li><h3 id="&#x975E;&#x7ED1;&#x5B9A;&#x7C7B;&#x65B9;&#x6CD5;-&#x5BF9;&#x8C61;&#x65B9;&#x6CD5;">&#x975E;&#x7ED1;&#x5B9A;&#x7C7B;&#x65B9;&#x6CD5; (&#x5BF9;&#x8C61;&#x65B9;&#x6CD5;)</h3>
<pre><code class="lang-py">  &#x975E;&#x7ED1;&#x5B9A;&#x7C7B;&#x65B9;&#x6CD5;&#x5C31;&#x662F;&#x7C7B;&#x4E2D;&#x53EF;&#x4EE5;&#x5141;&#x8BB8;&#x5BF9;&#x8C61;&#x4F7F;&#x7528;&#x7684;&#x65B9;&#x6CD5;,&#x5E26;&#x6709;&#x4E00;&#x4E2A;&#x5F62;&#x53C2;self&#x6765;&#x63A5;&#x53D7;&#x5BF9;&#x8C61;&#x8C03;&#x7528;&#x65F6;&#x9ED8;&#x8BA4;&#x4F20;&#x5165;&#x7684;&#x5BF9;&#x8C61;&#x503C;
  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Human</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">drink</span><span class="hljs-params">(self)</span>:</span>
          print(<span class="hljs-string">&apos;&#x975E;&#x7ED1;&#x5B9A;&#x7C7B;&#x65B9;&#x6CD5;,&#x5BF9;&#x8C61;&#x53EF;&#x4EE5;&#x8C03;&#x7528;&apos;</span>)
</code></pre>
</li>
<li><h3 id="&#x7C7B;&#x65B9;&#x6CD5;">&#x7C7B;&#x65B9;&#x6CD5;</h3>
<pre><code class="lang-py">  &#x7C7B;&#x65B9;&#x6CD5;&#x662F;&#x5728;&#x7C7B;&#x4E2D; &#x901A;&#x8FC7;@classmethod &#x8FDB;&#x884C;&#x58F0;&#x660E;, &#x9ED8;&#x8BA4;&#x5728;&#x8C03;&#x7528;&#x4ED6;&#x7684;&#x65F6;&#x5019;&#x4F1A;&#x5C06;&#x7C7B;&#x4F20;&#x5165;&#x65B9;&#x6CD5;&#x4E2D;&#x7531;cls&#x6765;&#x63A5;&#x6536;
  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Human</span>:</span>
<span class="hljs-decorator">      @classmethod</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">sleep</span><span class="hljs-params">(cls)</span>:</span>
          print(<span class="hljs-string">&apos;&#x7C7B;&#x65B9;&#x6CD5;,&#x9ED8;&#x8BA4;&#x4F1A;&#x5C06;&#x7C7B;&#x4F20;&#x8FDB;&#x6765;&#x7531;&#x5F62;&#x53C2;cls&#x63A5;&#x6536;&apos;</span>)
</code></pre>
</li>
<li><h3 id="&#x9759;&#x6001;&#x65B9;&#x6CD5;">&#x9759;&#x6001;&#x65B9;&#x6CD5;</h3>
<pre><code class="lang-py">  &#x9759;&#x6001;&#x65B9;&#x6CD5;&#x662F;&#x5728;&#x7C7B;&#x4E2D;,&#x901A;&#x8FC7;@staticmethod &#x8FDB;&#x884C;&#x58F0;&#x660E;, &#x5B9A;&#x4E49;&#x7684;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x88AB;&#x7C7B;&#x548C;&#x5BF9;&#x8C61;&#x4EFB;&#x610F;&#x8C03;&#x7528;,&#x4E0D;&#x7528;&#x5411;&#x9759;&#x6001;&#x65B9;&#x6CD5;&#x4E2D;&#x4F20;&#x5165;&#x4EFB;&#x4F55;&#x5BF9;&#x8C61;&#x548C;&#x7C7B;.
  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Human</span>:</span>
<span class="hljs-decorator">      @staticmethod</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">run</span><span class="hljs-params">()</span>:</span>
          print(<span class="hljs-string">&apos;&#x9759;&#x6001;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x88AB;&#x5BF9;&#x8C61;&#x548C;&#x7C7B;&#x968F;&#x610F;&#x8C03;&#x7528;,&#x4E0D;&#x9700;&#x8981;&#x4F20;&#x5165;&#x7C7B;&#x548C;&#x5BF9;&#x8C61;&apos;</span>)
</code></pre>
</li>
<li><h4 id="&#x7C7B;&#x65B9;&#x6CD5;&#x548C;&#x9759;&#x6001;&#x65B9;&#x6CD5;&#x8BD5;&#x9898;">&#x7C7B;&#x65B9;&#x6CD5;&#x548C;&#x9759;&#x6001;&#x65B9;&#x6CD5;&#x8BD5;&#x9898;</h4>
<p>  <img src="../images/&#x7C7B;&#x65B9;&#x6CD5;&#x548C;&#x9759;&#x6001;&#x65B9;&#x6CD5;&#x8BD5;&#x9898;.jpg" alt=""></p>
<pre><code class="lang-py">  <span class="hljs-comment"># &#x7C7B;&#x65B9;&#x6CD5;&#x9ED8;&#x8BA4;&#x5728;&#x8C03;&#x7528;&#x4ED6;&#x7684;&#x65F6;&#x5019;&#x4F1A;&#x5C06;&#x7C7B;&#x4F20;&#x5165;&#x65B9;&#x6CD5;&#x4E2D;&#x7531;cls&#x6765;&#x63A5;&#x6536;</span>
  <span class="hljs-comment"># &#x9759;&#x6001;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x88AB;&#x7C7B;&#x548C;&#x5BF9;&#x8C61;&#x4EFB;&#x610F;&#x8C03;&#x7528;,&#x4E0D;&#x7528;&#x5411;&#x9759;&#x6001;&#x65B9;&#x6CD5;&#x4E2D;&#x4F20;&#x5165;&#x4EFB;&#x4F55;&#x5BF9;&#x8C61;&#x548C;&#x7C7B;.</span>

  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">A</span><span class="hljs-params">(object)</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">foo</span><span class="hljs-params">(self, x)</span>:</span>
          print(<span class="hljs-string">&apos;executing foo(%s, %s)&apos;</span> % (self, x))

<span class="hljs-decorator">      @classmethod</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">class_foo</span><span class="hljs-params">(cls, x)</span>:</span>
          print(<span class="hljs-string">&apos;executing class_foo(%s, %s)&apos;</span> %(cls, x))

<span class="hljs-decorator">      @staticmethod</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">static_foo</span><span class="hljs-params">(x)</span>:</span>
          print(<span class="hljs-string">&apos;executing static_foo(%s)&apos;</span> % x)

  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
      a = A()
      a.foo(<span class="hljs-string">&apos;kafka1&apos;</span>)
      a.class_foo(<span class="hljs-string">&apos;kafka2&apos;</span>)
      a.static_foo(<span class="hljs-string">&apos;kafka3&apos;</span>)
</code></pre>
</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../home/8.面向对象/3.魔术方法.html" class="navigation navigation-prev " aria-label="Previous page: 魔术方法"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../home/8.面向对象/5.抽象类.html" class="navigation navigation-next " aria-label="Next page: 抽象类"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
